<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('审核列表列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>申请时间：</label>
                                <input type="text" class="time-input" placeholder="请选择申请时间" name="createTime"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "business/carPackageAudit";

        $(function() {
            var options = {
                url: prefix + "/list",
                modalName: "审核列表",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'instanceId',
                    title: '流程实例id',
                    visible: false
                },
                {
                    field: 'serviceItem.id',
                    title: '套餐id',
                    visible:false
                },
                {
                    field: 'serviceItem.name',
                    title: '套餐名称',
                },
                {
                    field: 'serviceItem.discountPrice',
                    title: '套餐价格',
                },
                {
                    field: 'serviceItem.info',
                    title: '套餐备注',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 5);
                    }
                },
                {
                    field: 'createByName',
                    title: '申请人'
                },
                {
                    field: 'createTime',
                    title: '申请时间'
                },
                {
                    field: 'taskName',
                    title: '当前节点'
                },
                {
                    field: 'taskId',
                    title: '当前节点id',
                    visible: false
                },
                {
                    field: 'statusInfo',
                    title: '审核状态'
                },
                {
                    field: 'auditors',
                    title: '当前审核人'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var instanceId = row.instanceId;
                        var taskId = row.taskId;
                        var revokeFlag = (row.statusInfo === '审核中' | row.statusInfo === '审核拒绝') === 1;
                        var packageId = row.serviceItem.id;
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="historicAudit(' + instanceId + ')"><i class="fa fa-edit"></i>审批历史</a> ');
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="checkProgress(' + instanceId + ','+taskId+')"><i class="fa fa-info"></i>进度查看</a>');
                        if(revokeFlag){
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="revoke(' + instanceId + ','+packageId+')"><i class="fa fa-remove"></i>撤销</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function historicAudit(id){
            $.modal.open("审批历史", prefix + "/historicAudit/"+id);
        }
        function checkProgress(instanceId,taskId){
            $.modal.open("进度查看", prefix + "/checkProgress/"+instanceId+"/"+taskId);
        }
        function revoke(instanceId,packageId){
            $.modal.confirm("确认要撤销申请吗?", function() {
                $.get(prefix + "/revoke/"+instanceId+"/"+packageId,function (result) {
                    $.operate.ajaxSuccess(result);
                });
            });
        }
    </script>
</body>
</html>